/*
 * Copyright   2000   The Regents of the University of California
 * All Rights Reserved
 * 
 * Permission to use, copy, modify and distribute any part of Simgrid/SG
 * for educational, research and non-profit purposes, without fee, and
 * without a written agreement is hereby granted, provided that the above
 * copyright notice, this paragraph and the following three paragraphs
 * appear in all copies.
 * 
 * Those desiring to incorporate this Simgrid/SG into commercial
 * products or use for commercial purposes should contact the Technology
 * Transfer & Intellectual Property Services, University of California,
 * San Diego, 9500 Gilman Drive, Mail Code 0910, La Jolla, CA 92093-0910,
 * Ph: (858) 534-5815, FAX: (858) 534-7345, E-MAIL:invent@ucsd.edu.
 * 
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
 * INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS Simgrid/SG,
 * EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.  
 * 
 * THE Simgrid/SG PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND THE
 * UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
 * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.  THE UNIVERSITY OF
 * CALIFORNIA MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY
 * KIND, EITHER IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
 * PURPOSE, OR THAT THE USE OF THE Simgrid/SG WILL NOT INFRINGE ANY
 * PATENT, TRADEMARK OR OTHER RIGHTS.
 */

#ifndef SG_DATASTRUCTURES_H 
#define SG_DATASTRUCTURES_H

#include "tbx_fifo.h"
#include "sg_types.h"
#include "sg_tcp_types.h"

/* RESOURCE */
struct _SG_Resource {

  int global_index;

  SG_resource_t type;		/* type */
  SG_resourcesharing_t sharing_policy;	/* sharing */

  char *name;			/* name     */
  void *metadata;		/* metadata */

  /* SG_HOST */
  SG_Trace cpu_trace;
  SG_Trace failure_trace;
  long double cpu_offset;
  long double rel_speed;

  /* SG_LINK */
  SG_Trace latency_trace;
  long double latency_offset;
  SG_Trace bandwidth_trace;
  long double bandwidth_offset;
  SG_Trace max_bandwidth_trace;
  long double max_bandwidth_offset;

  /* TCP_LINK */
  tcp_link_data_t tcp_link_data;

  /* SG_ROUTE */
  tcp_route_data_t tcp_route_data;

  /* Tasks */
  TBX_FIFO_t tasks_running;
  TBX_FIFO_t tasks_failed;
  TBX_FIFO_t tasks_scheduled;	/* includes READY tasks */

};

/* TASK */
struct _SG_Task {

  char *name;			/* name        */
  void *metadata;		/* metatdata   */
  long double cost;			/* cost        */

  long double remains;		/* How much of that cost remains to
				   be done in the currently running task */

  long double start;			/* start time  */
  long double effective_start;	/* to deal with latency */

  long double finish;		/* finish time : this is modified during the run
				 * and fluctuates until the task is complete   
				 */

  SG_taskstate_t state;		/* state       */
  SG_Resource resource;		/* resource    */

  SG_task_t type;		/*" SG_COMPUTATION or SG_TRANSFER */

  /* priority */
  long double priority;
  long double priority_bak;          /* used for suspend and resume */


  /* parents */
  int nb_children;
  SG_Task *children;

  /* children */
  int nb_parents;
  SG_Task *parents;
};

/* END-TO-END-TRANSFER */
struct _SG_EndToEndTransfer {

  char *name;
  void *metadata;

  int nb_links;
  SG_Resource *links;

  long double packet_size;
  int nb_packets;

  SG_Task **packet_transfers;

  /* Virtual tasks so that the end-to-end  */
  /* transfer can be used as a normal task */
  SG_Task transfer_first;
  SG_Task transfer_last;
};

/* TRACE */
struct _SG_Trace {
  SG_trace_t type;		/* SG_DYNAMIC or SG_FIXED */

  /* Fixed */
  long double value;

  /* Dynamic */
  long double last_time;		/* TRACE_TIMESTEP + last point's time */
  long double total;			/* total integral */
  long double offset;		/* offset */

  char *filename;		/* data file */

  SG_TimeSeries *levels;
  int nb_levels;
};

/* PREDICTION */
struct _SG_Prediction {
  char *name;
  long double value;
};

/* TIMESERIES */
struct _SG_TimeSeries {
  long nb_points;
  long double spacing;
  long double *values;		/* Array of size nb_points */
};

#endif				/* SG_DATASTRUCTURES_H */
